package com.ziki.common.interceptor;

import com.ziki.common.util.CommonUtil;
import org.apache.commons.codec.digest.Md5Crypt;

/**
 * @author pty
 * @version V1.0
 * @Package com.ziki.common.interceptor
 * @date 2024/4/13 18:00
 */
public class SaultTest {

    public static void main(String[] args) {
        String inputString = "Hello, World!";
        String randomSalt = "$1$" + CommonUtil.getRandomCode(8);
        System.out.println("randomSalt:  " + randomSalt + "存入数据库");
        // register：使用 Md5Crypt.md5Crypt() 进行字符串的 MD5 加密
        String saltedInfo = Md5Crypt.md5Crypt(inputString.getBytes(), randomSalt);
        System.out.println("加盐后的：" + saltedInfo);
        // login：还是利用原来的随机盐来获取密码对比
        String saltInfo2 = Md5Crypt.md5Crypt(inputString.getBytes(), randomSalt);
        System.out.println("加盐对比" + saltInfo2);
        if (saltInfo2.equals(saltedInfo)) {
            System.out.println("success");
        }
    }
}
